﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace MyResKit
{
	/// <summary>
	/// 职责:资源的抽象
	/// </summary>
	public class Res
	{
		public string Name { get; private set; }

		public Res(string assetName)
		{
			Name = assetName;
		}
		
		protected Object mAsset;
		
		public Object Asset
		{
			get { return mAsset; }
		}
		
		private int mReferenceCount = 0;

		public void Retain()
		{
			mReferenceCount++;
		}

		public void Release()
		{
			mReferenceCount--;

			if (mReferenceCount == 0)
			{
				Unload();

				ResMgr.SharedLoadedReses.Remove(this);
				
				mAsset = null;
			}
		}


		public virtual void Load()
		{
			
		}

		protected virtual void Unload()
		{
			
		}
	}
}